package com.tsmti.lab.controller.technician;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.tsmti.core.common.controller.BaseCrudController;
import com.tsmti.core.common.model.AjaxJson;
import com.tsmti.core.common.query.data.Page;
import com.tsmti.core.common.query.data.PageJson;
import com.tsmti.core.common.query.data.PropertyPreFilterable;
import com.tsmti.core.common.query.data.Queryable;
import com.tsmti.core.util.StringUtils;
import com.tsmti.lab.dto.PimsPathologyPiecesView;
import com.tsmti.lab.entity.PimsPathologyPieces;
import com.tsmti.lab.service.EmbedService;
import com.tsmti.shiro.annotation.RequiresPathPermission;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 包埋管理
 *
 * @auther ShiYan.Shi
 * @create 2018/11/17  15:52
 */
@Controller
@RequestMapping("/technician/embed")
@RequiresPathPermission("technician:embed")
public class EmbedController extends BaseCrudController<PimsPathologyPieces,Long> {
    private static Logger logger = Logger.getLogger(EmbedController.class);

    @Autowired
    private EmbedService embedService;


    @Override
    public void ajaxList(Queryable queryable, PropertyPreFilterable propertyPreFilterable, HttpServletRequest request, HttpServletResponse response) throws IOException {
        super.ajaxList(queryable, propertyPreFilterable, request, response);
    }

    @RequestMapping(value = "dataQuery", method = {RequestMethod.GET, RequestMethod.POST})
    public void dataQuery(@ModelAttribute PimsPathologyPiecesView model, Queryable queryable, PropertyPreFilterable propertyPreFilterable, HttpServletRequest request,
                        HttpServletResponse response) throws IOException {
        System.out.println(model.toString());
        // 将实体类传入后台中
//        model.setOrgId(UserUtils.getOrgId());
        int total = embedService.getListTotal(model);
        Page<PimsPathologyPiecesView> list = embedService.getDataByQueryCondition(model, queryable, total);
        PageJson<PimsPathologyPiecesView> pageJson = new PageJson<>(list);
        SerializeFilter filter = propertyPreFilterable.constructFilter(PimsPathologyPiecesView.class);
        String content = JSON.toJSONString(pageJson, filter);
        StringUtils.printJson(response, content);
    }

    @RequestMapping(value = "dataInfoByID", method = {RequestMethod.GET})
    @ResponseBody
    public AjaxJson dataInfoByID(@RequestParam(value = "id", required = true, defaultValue = "") Long id) throws IOException {
        System.out.println(id);
        PimsPathologyPiecesView pimsPathologyPiecesView = embedService.getDetialInfo(id);
        AjaxJson ajaxJson = AjaxJson.success("操作成功");
        ajaxJson.setData(pimsPathologyPiecesView);
        return ajaxJson;
    }

}
